<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>缩放动画效果</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }

        .container {
            text-align: center;
            padding: 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            max-width: 500px;
            width: 100%;
        }

        .demo-box {
            width: 200px;
            height: 200px;
            margin: 20px auto;
            background-color: #FF9800;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            border-radius: 8px;
        }

        .controls {
            margin-top: 20px;
        }

        button {
            padding: 10px 20px;
            margin: 0 10px;
            border: none;
            border-radius: 4px;
            background-color: #2196F3;
            color: white;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }

        button:hover {
            background-color: #0b7dda;
        }

        .scale-in {
            animation: scaleIn 0.5s ease-out forwards;
            transform: scale(0);
        }

        .scale-out {
            animation: scaleOut 0.5s ease-in forwards;
        }

        .scale-up {
            animation: scaleUp 0.5s ease-out forwards;
        }

        .scale-down {
            animation: scaleDown 0.5s ease-in forwards;
        }

        @keyframes scaleIn {
            from { transform: scale(0); }
            to { transform: scale(1); }
        }

        @keyframes scaleOut {
            from { transform: scale(1); }
            to { transform: scale(0); }
        }

        @keyframes scaleUp {
            from { transform: scale(1); }
            to { transform: scale(1.5); }
        }

        @keyframes scaleDown {
            from { transform: scale(1); }
            to { transform: scale(0.5); }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>缩放动画效果</h1>
        <div class="demo-box" id="demoBox">缩放效果</div>
        <div class="controls">
            <button onclick="scaleIn()">缩小进入</button>
            <button onclick="scaleOut()">缩小退出</button>
            <button onclick="scaleUp()">放大</button>
            <button onclick="scaleDown()">缩小</button>
            <button onclick="resetAnimation()">重置</button>
        </div>
        <div class="code-section">
            <h3>CSS代码:</h3>
            <pre><code>.scale-in {
  animation: scaleIn 0.5s ease-out forwards;
  transform: scale(0);
}

.scale-out {
  animation: scaleOut 0.5s ease-in forwards;
}

.scale-up {
  animation: scaleUp 0.5s ease-out forwards;
}

.scale-down {
  animation: scaleDown 0.5s ease-in forwards;
}

@keyframes scaleIn {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

@keyframes scaleOut {
  from { transform: scale(1); }
  to { transform: scale(0); }
}

@keyframes scaleUp {
  from { transform: scale(1); }
  to { transform: scale(1.5); }
}

@keyframes scaleDown {
  from { transform: scale(1); }
  to { transform: scale(0.5); }
}</code></pre>
        </div>
    </div>

    <script>
        const box = document.getElementById('demoBox');

        function scaleIn() {
            resetAnimation();
            box.classList.add('scale-in');
        }

        function scaleOut() {
            resetAnimation();
            box.classList.add('scale-out');
        }

        function scaleUp() {
            resetAnimation();
            box.classList.add('scale-up');
        }

        function scaleDown() {
            resetAnimation();
            box.classList.add('scale-down');
        }

        function resetAnimation() {
            box.classList.remove('scale-in', 'scale-out', 'scale-up', 'scale-down');
            // 触发重绘
            void box.offsetWidth;
        }
    </script>
</body>
</html>